package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"os"
	"strings"
)

var showtags = flag.Bool("showtags", false, "show non-text nodes")
var fontpath = flag.String("font", os.Getenv("font"), "default font")

func init() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options] [url]\n", os.Args[0])
		fmt.Fprintln(os.Stderr, "options:")
		flag.PrintDefaults()
	}
	flag.Parse()
	render_init()
}

func cleanup() {
	disp.Close()
}

func die(e error) {
	if e != nil {
		cleanup()
		log.Fatal(e)
	}
}

func main() {
	target := "http://www.google.com/"
	if len(flag.Args()) > 0 {
		target = flag.Arg(0)
		if strings.Contains(target, "://") == false {
			target = "http://" + target
		}
	}
	res, err := http.Get(target)
	die(err)
	renderPage(res.Body)
	redraw(false)
	go domouse()
	dokb()
	cleanup()
}
